package com.qys.livesMall.product.controller.sys;


import com.qys.livesMall.common.result.R;
import com.qys.livesMall.product.entity.H2ProductSku;
import com.qys.livesMall.product.model.dto.AddAttrOptions;
import com.qys.livesMall.product.model.dto.DelAttrOptions;
import com.qys.livesMall.product.model.dto.EditProductSku;
import com.qys.livesMall.product.model.vo.AddAttrOptionsVO;
import com.qys.livesMall.product.service.H2ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *  前端控制器
 * @author gmx
 * @since 2023-05-17
 */
@RestController
@RequestMapping("/h2-shop-sku")
public class H2ProductSkuController {

    /**
     * 新增规格值
     */
    @Autowired
    private H2ProductSkuService skuService;
    @PostMapping("/add")
    public R<AddAttrOptionsVO> add(@RequestBody AddAttrOptions attrOptions){
        return R.ok(skuService.add(attrOptions));
    }

    /**
     * 修改sku
     * @param editSku
     * @return
     */
    @PostMapping("/upd")
    public R add(@RequestBody EditProductSku editSku){
        skuService.upd(editSku);
        return R.ok();
    }

    /**
     * 删除规格值
     * @param attrOptions
     * @return
     */
    @PostMapping("/del")
    public R<List<H2ProductSku>> del(@RequestBody DelAttrOptions attrOptions){
        return R.ok(skuService.del(attrOptions));
    }
}
